#ifndef LUA_WRAPER_H
#define LUA_WRAPER_H


#include <string.h>
#include <QString>
#include <iostream>
#include<typeinfo>
#include <QDebug>


extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
#include "lua_bind.h"


class LuaDelegate{
public:
    LuaDelegate();
    int DoFile(QString);
    void Stop();
    int DoString(QString);
    int UpdateScript(QString);

    void pushstack() {
//        const std::type_info &t1 = std::bad_typeid(arg1);
//        std::cout << t1.name() << std::endl;
    }
    //单参数模板
    template <typename T,typename ... Types>
    void pushstack(T arg1,Types... rest) {
        const std::type_info &t1 = typeid(arg1);
        qDebug() <<arg1 << " "<< t1.name() << " type ";
        pushstack(rest...);
    }
    template<typename... T>//类的成员函数是模板
    void CallFuntion(QString name,T... para){
        int i = lua_getglobal(mVM,name.toStdString().c_str());
        if(i < 0){
            return ;
        }
        pushstack(para...);
    }
    void PrintError(lua_State *L);
    /* 收到数据发送给lua层进行处理*/
    void OnSerialData(QString);
    void OnNetworkData(char*,char*,uint32_t port);
    void OnNewTcpClient(QString ip,uint32_t port,uint32_t sockptr);
    void OnClientLeave(QString ip,uint32_t port,uint32_t sockptr);
    void ClearShowBuffer();

    void DumpStack();

    ~LuaDelegate();
private:
    lua_State *mVM;
    QString mFile;
};

void TestLua();


#endif // LUA_WRAPER_H

